package com.me.blood;

import android.text.TextUtils;

import com.me.ad.ADType;
import com.me.utils.Constant;
import com.me.utils.Pref;
import com.toutiao.base.BaseAdApp;
import com.umeng.commonsdk.UMConfigure;

public abstract class BaseApp extends BaseAdApp {

    @Override
    public void onCreate() {
        super.onCreate();
        UMConfigure.preInit(this, Constant.UM, "");

        if (Pref.getInstance(this).getBoolean("agree", false)) {
            initSdk();
        }
    }

    public void initSdk() {
        UMConfigure.init(App.getApp(), Constant.UM, "", UMConfigure.DEVICE_TYPE_PHONE, "");
        initTrack(getString(R.string.app_name));
    }

    public boolean isEnable(ADType type) {
        if (getAdBean() == null || TextUtils.isEmpty(getAdBean().appId)) {
            initTrack(getString(R.string.app_name));
            return false;
        }
        if (type == null) {
            return false;
        }
        if (type.getName().contains("insert")) {
            if ("0".equals(adMap.get(ADType.XP.getName()))) {
                return false;
            }
        } else if (type.getName().contains("video")) {
            if ("0".equals(adMap.get(ADType.REWARD.getName()))) {
                return false;
            }
        }
        String v = adMap.get(type.getName());
        if ("1".equals(v)) {
            return true;
        }
        if (type == ADType.SPLASH && "2".equals(v)) {
            return true;
        }
        return false;
    }

    private boolean first = true;

    public boolean isMultiSplash() {
        boolean bo = first && "2".equals(adMap.get(ADType.SPLASH.getName()));
        if (bo) {
            first = false;
        }
        return bo;
    }
}
